home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / Players / DDrawXCL / ddrawobj.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  4.8 KB  |  116 lines

  1. //------------------------------------------------------------------------------
  2. // File: DDrawObj.h
  3. //
  4. // Desc: DirectShow sample code - DDraw Object class header file.
  5. //
  6. // Copyright (c) 1993-2001 Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9.  
  10. // #define NOFLIP  1  /* for debugging */
  11.  
  12.  
  13. // Define ball radius
  14. #define BALL_RADIUS   40
  15. #define BALL_STEP      4
  16.  
  17. //
  18. // Some macros
  19. //
  20. #define RECTWIDTH(rect)   ((rect).right  - (rect).left)
  21. #define RECTHEIGHT(rect)  ((rect).bottom - (rect).top)
  22.  
  23. // forward declaration
  24. class COverlayCallback ;
  25.  
  26. //
  27. // DDraw object class to paint color key, flip etc etc.
  28. //
  29. class CDDrawObject {
  30. public:   // public methods for Windows structure to call
  31.     CDDrawObject(HWND hWndApp) ;
  32.     ~CDDrawObject(void) ;
  33.     
  34.     BOOL    Initialize(HWND hWndApp) ;
  35.     HRESULT StartExclusiveMode(HWND hWndApp) ;
  36.     HRESULT StopExclusiveMode(HWND hWndApp) ;
  37.     HRESULT UpdateAndFlipSurfaces(void) ;
  38.     void    SetVideoPosition(DWORD dwVideoLeft, DWORD dwVideoTop, 
  39.                              DWORD dwVideoWidth, DWORD dwVideoHeight) ;
  40.     void    SetBallPosition(DWORD dwVideoLeft, DWORD dwVideoTop, 
  41.                             DWORD dwVideoWidth, DWORD dwVideoHeight) ;
  42.     void    MoveBallPosition(int iDirX, int iDirY) ;
  43.     inline  void    SetColorKey(DWORD dwColorKey)   { m_dwVideoKeyColor = dwColorKey ; } ;
  44.     inline  void    GetScreenRect(RECT *pRect)      { *pRect = m_RectScrn ; } ;
  45.     inline  BOOL    IsInExclusiveMode(void)         { return m_bInExclMode ; } ;
  46.     inline  LPDIRECTDRAW         GetDDObject(void)  { return m_pDDObject ; } ;
  47.     inline  LPDIRECTDRAWSURFACE  GetDDPrimary(void) { return m_pPrimary ; } ;
  48.     inline  void    SetOverlayState(BOOL bState)    { m_bOverlayVisible = bState ; } ;
  49.     inline  IDDrawExclModeVideoCallback * GetCallbackInterface(void) { return m_pOverlayCallback ; } ;
  50.     
  51. private:  // private helper methods for the class' own use
  52.     HRESULT FillSurface(IDirectDrawSurface *pDDSurface) ;
  53.     void    DrawOnSurface(LPDIRECTDRAWSURFACE pSurface) ;
  54.     HRESULT ConvertColorRefToPhysColor(COLORREF rgb, DWORD *pdwPhysColor) ;
  55.     inline  DWORD   GetColorKey(DWORD dwColorKey)   { return m_dwVideoKeyColor ; } ;
  56.     inline  void    IncCount(void)                  { m_iCount++ ; } ;
  57.     inline  int     GetCount(void)                  { return m_iCount ; } ;
  58.     
  59. private:  // internal state info
  60.     LPDIRECTDRAW         m_pDDObject ;   // DirectDraw interface
  61.     LPDIRECTDRAWSURFACE  m_pPrimary ;    // primary surface
  62.     LPDIRECTDRAWSURFACE  m_pBackBuff ;   // back buffer attached to primary
  63.     
  64.     BOOL     m_bInExclMode ;     // Are we in exclusive mode now?
  65.     RECT     m_RectScrn ;        // whole screen as a rect
  66.     RECT     m_RectVideo ;       // current video position as rect
  67.     DWORD    m_dwScrnColor ;     // physical color for surface filling
  68.     DWORD    m_dwVideoKeyColor ; // physical color for color keying video area
  69.     int      m_iCount ;          // flip count
  70.     int      m_iBallCenterX ;    // X-coord of ball's center
  71.     int      m_iBallCenterY ;    // Y-coord of ball's center
  72.     BOOL     m_bFrontBuff ;      // draw on front (or back) buffer?
  73.     LPTSTR   m_szFrontMsg ;      // front surface string ("Front Buffer")
  74.     LPTSTR   m_szBackMsg ;       // back surface string ("Back Buffer")
  75.     LPTSTR   m_szDirection ;     // Direction string for users
  76.     HPEN     m_hPen ;            // pen for drawing outline of the ball
  77.     HBRUSH   m_hBrush ;          // brush for filling the ball
  78.     BOOL     m_bOverlayVisible ; // is overlay visible?
  79.     IDDrawExclModeVideoCallback *m_pOverlayCallback ;  // overlay callback handler interface
  80. } ;
  81.  
  82.  
  83.  
  84. //
  85. // Overlay callback handler object class
  86. //
  87. class COverlayCallback : public CUnknown, public IDDrawExclModeVideoCallback
  88. {
  89. public:
  90.     COverlayCallback(CDDrawObject *pDDrawObj, HWND hWndApp, HRESULT *phr) ;
  91.     ~COverlayCallback() ;
  92.  
  93.     DECLARE_IUNKNOWN
  94.     //
  95.     // IDDrawExclModeVideoCallback interface methods
  96.     //
  97.     STDMETHODIMP OnUpdateOverlay(BOOL  bBefore,
  98.                                  DWORD dwFlags,
  99.                                  BOOL  bOldVisible,
  100.                                  const RECT *prcSrcOld,
  101.                                  const RECT *prcDestOld,
  102.                                  BOOL  bNewVisible,
  103.                                  const RECT *prcSrcNew,
  104.                                  const RECT *prcDestNew) ;
  105.  
  106.     STDMETHODIMP OnUpdateColorKey(COLORKEY const *pKey,
  107.                                   DWORD    dwColor) ;
  108.  
  109.     STDMETHODIMP OnUpdateSize(DWORD dwWidth, DWORD dwHeight, 
  110.                               DWORD dwARWidth, DWORD dwARHeight) ;
  111.  
  112. private:
  113.     CDDrawObject *m_pDDrawObj ;
  114.     HWND          m_hWndApp ;
  115. } ;
  116.